package com.lzzy;

import java.io.*;
import java.util.Scanner;

public class Encryption_And_Decryption {
    // 加密
    public static void encyText() throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个需要加密文件名：");
        String stc = sc.nextLine();
        // 读入需要加密的文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("G:\\桌面\\" + stc));
        Scanner sc1 = new Scanner(System.in);
        System.out.print("请输入一个加密后的文件名：");
        String stc1 = sc.nextLine();
        // 写出加密文件
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("G:\\桌面\\" + stc1));
        // 判断是否读取到文件末尾

        int b = 0;
        while ((b = bis.read())!= -1){
            bos.write(b+5);
        }

        bis.close();
        bos.close();

    }


    // 解密
    public static void decodeText() throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个需要解密文件名：");
        String stc = sc.nextLine();
        // 读入解密的文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("G:\\桌面\\" + stc));
        Scanner sc1 = new Scanner(System.in);
        System.out.print("请输入一个解密后的文件名：");
        String stc1 = sc.nextLine();
        // 写出解密文件
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("G:\\桌面\\"+stc1));
        // 判断是否读取到文件末尾

        int b = 0;
        while ((b = bis.read())!= -1){
            bos.write(b-5);
        }

        bis.close();
        bos.close();

    }

    public static void main(String[] args) throws Exception{
//        encyText();
        decodeText();
    }
}
